package com.atguigu.sparkcore.rdd.tranformsinglevale

import com.atguigu.sparkcore.util.MySparkContextUtil
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * rdd转换-Filter
  * 传入一个function,返回function返回为true的结果
  */
object Filter {

  def main(args: Array[String]): Unit = {

    // 获取sparkContext
    val sc = MySparkContextUtil.get(args)

    // 创建rdd
    val list: Array[Int] = Array(10, 21, 30, 40, 50, 61)
    val rdd: RDD[Int] = sc.makeRDD(list, 2)

    // 转换rdd
    val result = rdd.filter(x => x % 2 == 0)

    // 输出
    println(result.collect().mkString(","))

    // 关闭资源
    MySparkContextUtil.close(sc)
  }
}
